package com.yanchi.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yanchi
 * @date 2022/1/18 9:36
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {

    @HystrixCommand(fallbackMethod = "demoFallBack",defaultFallback = "defaultFallBack")
    @GetMapping("demo")
    public String demo(Integer id){
        if (id <= 0){
            throw new RuntimeException("id 不符合");
        }
        return "demo ok!";
    }

    public String defaultFallBack(){
        return "默认熔断方法";
    }

    public String demoFallBack(Integer id){
        return "服务被熔断";
    }

}
